class Food
{
    constructor(el){
        this.el = el;
        this.width = 20;
        this.height = 20;
        this.foodX = 0;
        this.foodY = 0;
    }

    create(){
        let divObj = document.createElement('div');
        divObj.style.width = this.width + 'px';
        divObj.style.height = this.height + 'px';
        divObj.style.background = 'blue';
        divObj.style.position = 'absolute';

        this.foodObj = divObj;
        this.el.appendChild(this.foodObj);

        this.move();
    }

    move(){
        let foodXMaxNum = this.el.clientWidth/this.width - 1;
        let foodYMaxNum = this.el.clientHeight/this.height - 1;
        this.foodX = Math.floor(Math.random()*(foodXMaxNum-0+1)+0)*this.width;
        this.foodY = Math.floor(Math.random()*(foodYMaxNum-0+1)+0)*this.height;
        this.foodObj.style.left = this.foodX + 'px';
        this.foodObj.style.top = this.foodY + 'px';
    }
}